package com.elminster.graphic.entity;

public class GraphicEntity implements Comparable<GraphicEntity> {

    private Object label;
    private double value;
    
    public GraphicEntity() {
        super();
    }

    public GraphicEntity(Object label, double value) {
        super();
        this.label = label;
        this.value = value;
    }

    /**
     * @return the label
     */
    public Object getLabel() {
        return label;
    }
    
    /**
     * @param label the label to set
     */
    public void setLabel(Object label) {
        this.label = label;
    }
    
    /**
     * @return the value
     */
    public double getValue() {
        return value;
    }
    
    /**
     * @param value the value to set
     */
    public void setValue(double value) {
        this.value = value;
    }
    
    public void add(GraphicEntity other) {
        if (null == other) {
            return;
        }
        value += other.getValue();
    }
    
    public boolean equals(Object other) {
        if (other instanceof GraphicEntity) {
            GraphicEntity entity = (GraphicEntity) other;
            if (null != this.label) {
                return this.label.equals(entity.getLabel());
            }
        }
        return false;
    }

    public int compareTo(GraphicEntity o) {
        return this.getValue() - o.getValue() > 0 ? 1 : this.getValue() == o.getValue() ? 0 : -1;
    }
}
